﻿@model Xms.Web.Customize.Models.CreateFilterRuleModel

<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">
            <a data-toggle="collapse"
               href="#collapseTwo">
                <strong>@app.PrivilegeTree?.LastOrDefault().DisplayName</strong>
            </a>
        </h3>
    </div>
    <div id="collapseTwo" class="panel-collapse collapse in">
        <div class="panel-body">
            <form action="/@app.OrganizationUniqueName/customize/@app.ControllerName/@app.ActionName" method="post" id="editform" class="form-horizontal" role="form" data-autoreset="true">
                @Html.AntiForgeryToken()
                @Html.ValidationSummary()
                @Html.HiddenFor(x => x.EntityId)
                @Html.HiddenFor(x => x.Conditions)
                <div class="form-group col-sm-12">
                    <label class="col-sm-2 control-label">实体</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control input-sm hide" id="entityselecter" />
                    </div>
                </div>
                <div class="form-group col-sm-12">
                    @Html.LabelFor(x => x.Name, "名称", new { @class = "col-sm-2 control-label" })
                    <div class="col-sm-10">
                        @Html.TextBoxFor(x => x.Name, new { @class = "form-control required", @autofocus = true })
                    </div>
                </div>
                <div class="form-group col-sm-12">
                    @Html.LabelFor(x => x.EventName, "触发事件", new { @class = "col-sm-2 control-label" })
                    <div class="col-sm-10">
                        <select class="form-control" name="EventName" id="EventName">
                            <option value="create">@app.T["security_create"]</option>
                            <option value="update">@app.T["security_update"]</option>
                            <option value="delete">@app.T["security_delete"]</option>
                            <option value="share">@app.T["security_share"]</option>
                            <option value="assign">@app.T["security_assign"]</option>
                        </select>
                    </div>
                </div>
                <div class="form-group col-sm-12">
                    @Html.LabelFor(x => x.ToolTip, "提示信息", new { @class = "col-sm-2 control-label" })
                    <div class="col-sm-10">
                        @Html.TextBoxFor(x => x.ToolTip, new { @class = "form-control", @autofocus = true })
                    </div>
                </div>
                <div class="form-group col-sm-12">
                    <label class="col-sm-2 control-label">条件</label>
                    <div class="col-sm-10">
                        <button type="button" class="btn btn-info btn-sm" id="editFitlerBtn">
                            <span class="glyphicon glyphicon-filter"></span> 触发条件
                        </button>
                    </div>
                </div>
                <div class="form-group col-sm-12">
                    @Html.LabelFor(x => x.StateCode, app.T["StateCode"], new { @class = "col-sm-2 control-label" })
                    <div class="col-sm-10">
                        <label class="checkbox-inline">
                            @Html.RadioButtonFor(x => x.StateCode, Xms.Core.RecordState.Enabled, new { @class = "required radio-inline" }) @app.T["enabled"]
                        </label>
                        <label class="checkbox-inline">
                            @Html.RadioButtonFor(x => x.StateCode, Xms.Core.RecordState.Disabled, new { @class = "required radio-inline" }) @app.T["disabled"]
                        </label>
                    </div>
                </div>
                <div class="form-group col-sm-12 text-center" id="form-buttons">
                    <button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-saved"></span> @app.T["save"]</button>
                    <button type="reset" class="btn btn-default"><span class="glyphicon glyphicon-refresh"></span> @app.T["reset"]</button>
                </div>
            </form>
        </div>
    </div>
</div>
<div class="modal fade" id="FilterModal" tabindex="-1" role="dialog"
     aria-labelledby="FilterModalLabel" aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"
                        aria-hidden="true">
                    ×
                </button>
                <h4 class="modal-title" id="FilterModalLabel">
                    条件设置
                </h4>
            </div>
            <div class="modal-body">
                <div id="tabTabContent" class="tab-content">
                    <div class="tab-pane fade in active" style="padding:5px;">
                        <div class="form-group">
                            <div class="form-group">
                                <div class="col-sm-2"><label for="connection-logical">逻辑符：</label></div>
                                <div class="col-sm-3">

                                    <label><input type="radio" value="0" name="connection-logical" checked /> 并且</label>
                                    <label class="pl-3"><input type="radio" value="1" name="connection-logical" /> 或者</label>
                                </div>
                            </div>
                        </div>
                        <div class="form-group" id="FilterModalConditions">
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default"
                        data-dismiss="modal">
                    <span class="glyphicon glyphicon-remove"></span>
                    @app.T["dialog_close"]
                </button>
                <button type="button" class="btn btn-primary" id="saveFilterRule">
                    <span class="glyphicon glyphicon-ok"></span>
                    @app.T["dialog_ok"]
                </button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
@section Scripts {
    <script src="/content/js/jquery.form.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/jquery-validate/jquery.validate.min.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/jquery-validate/localization/messages_zh.min.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/fetch.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/form.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/bootstrap-datepicker-1.5.0/js/bootstrap-datepicker.min.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/filterdialog.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/customize/js/businessrule.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script>
        $(function () {
            //表单验证
            Xms.Web.Form($("#editform"), function (response) {
                if (response.IsSuccess) {
                    Xms.Web.Alert(true, response.Content, function () {
                        location.reload();
                    });
                    Xms.Web.Event.localStorageEvent.trigger('list_filterrule_rebind');

                }
                console.log(response);
            }, null, function (err) {
                var _Conditions = $('#Conditions').val();
                if (_Conditions == "") {
                    Xms.Web.Alert(false,'请先设置条件');
                    return false;
                }
            });
            $('#editFitlerBtn').on('click', function () {
                var _entityid = $('#EntityId').val();
                if (_entityid === '00000000-0000-0000-0000-000000000000') {
                    Xms.Web.Toast('请先选择实体', false);
                    return false;
                }
                businessModel.editFilter();
            });
            $('#saveFilterRule').on('click', function () {
                businessModel.saveFilter();
            });
            loadEntitys($('#entityselecter'));
        });
         function loadEntitys($context,callback) {
            var entitySelect = $context;
            entitySelect.entitySelector({
                rendered: function (self) {
                    var _entityid = $('#EntityId').val();
                    if (_entityid) {
                        var acli = self.listWrap.find('.xms-autoc-item[value="' + _entityid + '"]');
                        if (acli.length > 0) {
                            self.box.val(_entityid);
                            self.listWrap.hide();
                            self.vInput.val(acli.text());
                            self.value = acli.attr('value');
                            self.wrap.attr('data-isactive', false);
                            self.filterData();
                        }
                    }
                },
                submithandler: function (self, $this) {
                    $('#EntityId').val(self.value);
                   $('#Conditions').val('');
                },
                removehandler: function () {
                    $('#EntityId').val(self.value);
                    $('#Conditions').val('');
                },
                inputPlaceHolder:'选择实体'
            });

        }
    </script>
}